<?php
/**
 * admin asset manager
 * when render page , used by asset filter
 * @package Admin Libraries
 * @author luweijun <yiming_6weijun@163.com>
 * @copyright (c) YouKeTang 2013 
 */
class Admin_Asset {
    
    /**
     * invoke style before route called
     * @param type $type
     */
    public static function invoke($type = 'header') {
        if (is_callable("static::{$type}")) {
            static::$type();
        }
        
        $request = Laravel\Request::route();
        $controller = $request->controller;
        if (null === $controller) {
            $controller = Admin_Menu::get_top();
        }
        $action = $request->controller_action;
        if (null === $action) {
            $action = Admin_Menu::get_left();
        }
       
       if(!is_null($action) && !is_null($controller) && !empty($action) && !empty($controller) && 
                is_callable('static::'.  implode('_', array($controller,$action)))) {
            $fn = implode('_', array($controller,$action));
            static::$fn();
        }elseif (!is_null($action) && !empty ($action) && is_callable("static::$action")) {
            static::$action();
        } elseif (!is_null($controller) && !empty ($controller) && is_callable("static::$controller")) {
            static::$controller();
        }
    }
    
    /**
     * admin common css and scripts
     */
    private static function header() {
        Asset::container('header')->add('base', 'admin/css/base.css');
        Asset::container('header')->add('add-module-menu', 'admin/css/add-module-menu.css');
        Asset::container('header')->add('thickbox', 'thirdparty/thickbox/css/thickbox.css');
         Asset::container('header')->add('alertify-core','thirdparty/alertify/themes/alertify.core.css');
        Asset::container('header')->add('alertify-default','thirdparty/alertify/themes/alertify.default.css');

        Asset::container('header')->add('plug', 'common/js/plug/plug.js');
        Asset::container('header')->add('thickbox', 'thirdparty/thickbox/js/thickbox.js');
        Asset::container('header')->add('droppy', 'thirdparty/others/js/droppy.js');
        Asset::container('header')->add('helper', 'thirdparty/others/js/helper.js');
        Asset::container('header')->add('png', 'thirdparty/others/js/png.js');
        Asset::container('header')->add('alertify','thirdparty/alertify/alertify.min.js');
        Asset::container('header')->add('index', 'admin/js/buss/index.js');
        Asset::container('header')->add('operate', 'admin/js/buss/operate.js');
    }
    
    /**
     * backend user admin
     */
    private static function manager() {
        Asset::container('req')->add('footable','thirdparty/footable/css/footable-0.1.css');
        Asset::container('req')->add('footable.sortable','thirdparty/footable/css/footable.sortable-0.1.css');
        
        Asset::container('req')->add('footable','thirdparty/footable/js/footable-0.1.js');
        Asset::container('req')->add('footable.sortable','thirdparty/footable/js/footable.sortable.js');
        
        Asset::container('req')->add('theme','admin/css/theme.css');
    }
    
    /**
     * 新闻页样式
     */
    private static function news() {
        static::manager();
    }
    
    /**
     * 评论页面样式
     */
    private static function review() {
        static::manager();
    }
    
    /**
     * 视频页样式
     */
    private static function video() {
        static::manager();
        static::select2();
        Asset::container('req')->add('ajaxfileupload','admin/js/buss/ajaxfileupload.js');
    }
    
    /**
     * 分类样式
     */
    private static function category() {
        Asset::container('req')->add('jtree','thirdparty/jquerytree/css/jquery.treeview.css');
        Asset::container('req')->add('jtree','thirdparty/jquerytree/js/jquery.treeview.js');
        static::manager();
        static::select2();
    }

    /**
     * 公用的select2样式
     */
    private static function select2() {
        Asset::container('req')->add('select2','thirdparty/select2/select2.css');
        Asset::container('req')->add('select2','thirdparty/select2/select2.min.js');
    }
    
}
